﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin.product
{
    public partial class goodsprice1 : System.Web.UI.Page
    {


        // Methods
        private void Bind()
        {
            string sql = "select * from DB_memberank order by rankid asc";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.selectList1.Items.Add(new ListItem(row["rank"].ToString(), row["rankid"].ToString()));
                }
            }
        }

        private void Display(string parentid, string space)
        {
            string sql = "Select * From DB_Productclass Where parentid =" + parentid + " and languages=" + info.languages("") + " Order By classorder";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.typeid.Items.Add(new ListItem(space + "" + row["classname"].ToString() + "", "" + row["classid"].ToString() + ""));
                    this.Display(row["classid"].ToString(), "|-" + space);
                }
            }
        }

        protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
        {
            string str = re.replace(this.selectList1.SelectedValue.ToString());
            string str2 = re.replace(this.selectList2.SelectedValue.ToString());
            string sql = "select * from DB_Shoppro where visible=1";
            if (this.typeid.SelectedValue.ToString() != "0")
            {
                sql = sql + " and typeid in(" + re.returntype("0", this.typeid.SelectedValue.ToString(), info.languages("")) + ")";
            }
            DataTable table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    string str4;
                    if (str.ToString() == "-1")
                    {
                        if (str2.ToString() == "0")
                        {
                            str4 = string.Concat(new object[] { "update DB_Shoppro set proprice3=proprice3+(proprice3*(", Convert.ToSingle(this.price.Text), ")/100) where proid=", row["proid"].ToString(), "" });
                        }
                        else
                        {
                            str4 = string.Concat(new object[] { "update DB_Shoppro set proprice3=proprice3-(proprice3*(", Convert.ToSingle(this.price.Text), ")/100) where proid=", row["proid"].ToString(), "" });
                        }
                    }
                    if (str.ToString() == "0")
                    {
                        if (str2.ToString() == "0")
                        {
                            str4 = string.Concat(new object[] { "update DB_Shoppro set proprice1=proprice1+(proprice1*(", Convert.ToSingle(this.price.Text), ")/100) where proid=", row["proid"].ToString(), "" });
                        }
                        else
                        {
                            str4 = string.Concat(new object[] { "update DB_Shoppro set proprice1=proprice1-(proprice1*(", Convert.ToSingle(this.price.Text), ")/100) where proid=", row["proid"].ToString(), "" });
                        }
                    }
                    else if (str2.ToString() == "0")
                    {
                        str4 = string.Concat(new object[] { "update DB_Memberprice set price=price+(price*(", Convert.ToSingle(this.price.Text), ")/100) where productid=", row["proid"].ToString(), " and rankid=", str.ToString(), "" });
                    }
                    else
                    {
                        str4 = string.Concat(new object[] { "update DB_Memberprice set price=price-(price*(", Convert.ToSingle(this.price.Text), ")/100) where productid=", row["proid"].ToString(), " and rankid=", str.ToString(), "" });
                    }
                    SQLAccess.DoSql(str4);
                    base.Response.Write("<script language=javascript>alert('修改成功');location.href='goodsprice.aspx';</script>");
                    base.Response.End();
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='../login.aspx';</script>");
                base.Response.End();
            }
            this.ImageButton1.Attributes["onclick"] = "return CheckFrm()";
            if (!base.IsPostBack)
            {
                this.Bind();
                this.Display("0", "|--");
            }
        }

      
    }
}